//
//  DataSummaryTemperatureCell.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/25.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import UIKit
import Charts

class DataSummaryTemperatureCell: DataSummaryBloodOxygenCell {
    
    override func update(vm: DataSummaryCellViewModel, data: Any?) {
        super.update(vm: vm, data: data)
        
        guard let temData = (data as? SummaryDataModel)?.bodyTemperature else {
            showEmptyData()
            return
        }
        
        valueLabel.text = String(format: "%.1f", temData.bodyTemperature)
    }
    
    // 体温
    override var dataSet: LineChartDataSet {
        // TODO: 准确数据
        let entries = (0...24)
            .map({ $0 })
            .filter({ _ in Bool.random() })
            .map { i in
                ChartDataEntry(x: Double(i), y: Double((0...100).randomElement()!))
            }
        let dataSet = LineChartDataSet(entries: entries)
        setupDataSet(dataSet)
        return dataSet
    }
    
    override func showEmptyData() {
        valueLabel.text = "--"
    }
}
